package tw.twandroidproj.app.ui.Apply;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import tw.twandroidproj.app.R;

/**
 * Created by ZRP on 2016/5/13.
 */
public class resumePopupWindow extends PopupWindow {

    ListView resumeMenu;
    View resumeMenuView;
    public List<Map<String, Object>> resumeData = new ArrayList<Map<String, Object>>();
    SimpleAdapter resumeAdapter;
    Map<String, Object> map = new HashMap<String, Object>();

    resume_textShow callback;

    resumePopupWindow(Context context) {
//        callback = (resume_textShow) context;
        resumeMenuView = LayoutInflater.from(context).inflate(R.layout.apply_job, null);
        resumeMenu = (ListView) resumeMenuView.findViewById(R.id.resume_listView);
        resumeAdapter = new SimpleAdapter(context, getData(), R.layout.apply_resumeitem, new String[]{"resume_name"}, new int[]{R.id.resumeToJob_name});
        resumeMenu.setAdapter(resumeAdapter);


        //设置SelectPicPopupWindow的View  
        this.setContentView(resumeMenuView);
        //设置SelectPicPopupWindow弹出窗体的宽  
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        //设置SelectPicPopupWindow弹出窗体的高  
        this.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        //设置SelectPicPopupWindow弹出窗体可点击  
        this.setFocusable(true);
        //设置SelectPicPopupWindow弹出窗体动画效果  
        this.setAnimationStyle(R.style.AnimBottom);
        //实例化一个ColorDrawable颜色为半透明  
        ColorDrawable dw = new ColorDrawable(0x80000000);
        //设置SelectPicPopupWindow弹出窗体的背景  
        this.setBackgroundDrawable(dw);
        //mMenuView添加OnTouchListener监听判断获取触屏位置如果在选择框外面则销毁弹出框  
        resumeMenuView.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                int height = resumeMenu.getTop();
                int y = (int) event.getY();
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    if (y < height) {
                        dismiss();
                    }
                }

                return true;
            }
        });


        resumeMenu.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                callback.resumeSeclected(resumeData.get(position));
            }
        });

    }

    private List<Map<String,Object>> getData() {
        for (int i = 1; i <= 3; i++) {
            map.put("resume_name", "简历");
            resumeData.add(map);
        }
        return resumeData;
    }

    interface resume_textShow{
        void resumeSeclected(Map<String, Object> text);
    }
}
